//
//  PubuliuCollectionViewCell.m
//  瀑布流
//
//  Created by 刘家俊 on 17/4/25.
//  Copyright © 2017年 Andrew. All rights reserved.
//

#import "PubuliuCollectionViewCell.h"
#import <UIImageView+WebCache.h>
#import "PubuliuFrame.h"
#import "PubliuModel.h"
#import "UIImageView+BSExtension.h"

#define RGBColor(r, g, b,x) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:(x)]
#define Color(r, g, b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1.0]

@interface PubuliuCollectionViewCell ()

/** originalview */
@property (nonatomic,weak) UIView *originalView;
/** 图片 */
@property (nonatomic,weak) UIImageView *image;
/** 头像 */
@property (nonatomic,weak) UIImageView *photo;
/** 标题 */
@property (nonatomic,weak) UILabel *titleLabel;
/** 名称 */
@property (nonatomic,weak) UILabel *nameLabel;
/** 评论图标 */
@property (nonatomic,weak) UIImageView *commentImage;
/** 评论数 */
@property (nonatomic,weak) UILabel *commentLabel;
/** 点赞图标 */
@property (nonatomic,weak) UIButton *spotImage;
/** 点赞数 */
@property (nonatomic,weak) UILabel *spotLabel;

@end

@implementation PubuliuCollectionViewCell


- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        /** originalview */
        UIView *originalView = [[UIView alloc] init];
//        originalView.layer.cornerRadius = 8;
//        originalView.layer.masksToBounds = YES;
        originalView.backgroundColor = [UIColor whiteColor];
        [self addSubview:originalView];
        self.originalView = originalView;
        
        /** 图片 */
        UIImageView *image = [[UIImageView alloc] init];
        image.backgroundColor = Color(238, 238, 238);
        [originalView addSubview:image];
        self.image = image;
        
        /** 头像 */
        UIImageView *photo = [[UIImageView alloc] init];
        [originalView addSubview:photo];
        self.photo = photo;
        
        /** 标题 */
        UILabel *titleLabel = [[UILabel alloc] init];
        titleLabel.textColor = Color(21, 21, 21);
        titleLabel.font = [UIFont systemFontOfSize:13];
        titleLabel.numberOfLines = 0;
        [originalView addSubview:titleLabel];
        self.titleLabel = titleLabel;
        
        /** 名称 */
        UILabel *nameLabel = [[UILabel alloc] init];
        nameLabel.textColor = Color(21, 21, 21);
        nameLabel.font = [UIFont systemFontOfSize:11];
        [originalView addSubview:nameLabel];
        self.nameLabel = nameLabel;
        
        /** 评论图标 */
        UIImageView *commentImage = [[UIImageView alloc] init];
        [originalView addSubview:commentImage];
        self.commentImage = commentImage;
        
        /** 评论数 */
        UILabel *commentLabel = [[UILabel alloc] init];
        commentLabel.textColor = [UIColor lightGrayColor];
        commentLabel.font = [UIFont systemFontOfSize:11];
        [originalView addSubview:commentLabel];
        self.commentLabel = commentLabel;
        
        /** 点赞图标 */
        UIButton *spotImage = [[UIButton alloc] init];
        [spotImage setImage:[UIImage imageNamed:@"d-topic-heart@2x.png"] forState:UIControlStateNormal];
        [originalView addSubview:spotImage];
        self.spotImage = spotImage;
        
        /** 点赞数 */
        UILabel *spotLabel = [[UILabel alloc] init];
        spotLabel.font = [UIFont systemFontOfSize:11];
        spotLabel.textColor = [UIColor lightGrayColor];
        [originalView addSubview:spotLabel];
        self.spotLabel = spotLabel;
    }
    return self;
}

- (void)setFrameModel:(PubuliuFrame *)frameModel
{
    _frameModel = frameModel;
    
    /** originalview */
    self.originalView.frame = frameModel.originalView;
    
    /** 图片 */
    [self.image sd_setImageWithURL:[NSURL URLWithString:frameModel.model.image] placeholderImage:[UIImage imageNamed:@"loading"]];
    self.image.frame = frameModel.image;
    
    /** 头像 */
//    [self.photo sd_setImageWithURL:[NSURL URLWithString:frameModel.model.photo] placeholderImage:[UIImage imageNamed:@"loading"]];
    
    [self.photo bs_setCircleHeader:frameModel.model.photo placeholder:@"loading"];
    self.photo.frame = frameModel.photo;
    
    /** 标题 */
    self.titleLabel.text = frameModel.model.title;
    self.titleLabel.frame = frameModel.titleLabel;
    
    /** 名称 */
    self.nameLabel.text = frameModel.model.nickname;
    self.nameLabel.frame = frameModel.nameLabel;
    
    /** 评论图标 */
    self.commentImage.image = [UIImage imageNamed:@"d-choice-speech.png"];
    self.commentImage.frame = frameModel.commentImage;
    
    /** 评论数 */
    self.commentLabel.text = frameModel.model.pv;
    self.commentLabel.frame = frameModel.commentLabel;
    
    /** 点赞图标 */
    self.spotImage.frame = frameModel.spotImage;
    
    /** 点赞数 */
    self.spotLabel.text = frameModel.model.pv;
    self.spotLabel.frame = frameModel.spotLabel;
}

@end
